package com.gome.axwl.aoc.facade.impl;

import com.gome.axwl.aoc.common.util.BeanJsonUtil;
import com.gome.axwl.aoc.entity.dto.dataDrictionary.DataDictionaryItemDto;
import com.gome.axwl.aoc.entity.po.DataDictionaryItemPo;
import com.gome.axwl.aoc.facade.DataDictionaryFacadeService;
import com.gome.axwl.aoc.service.DataDictionaryService;
import com.gome.commons.core.ErrorCode;
import com.gome.commons.core.ResultData;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Auther: yinyuxin@gome.com.cn
 * @Date: 2018/7/16 16:50
 */
@Service("dataDictionaryFacadeService")
public class DataDictionaryFacadeServiceImpl implements DataDictionaryFacadeService {

    private static final Logger LOGGER=LoggerFactory.getLogger(DataDictionaryFacadeServiceImpl.class);

    @Autowired
    private DataDictionaryService dataDictionaryService;

    @Override
    public ResultData<List<DataDictionaryItemDto>> queryItemListByTypeCode(String typeCode) {
        ResultData<List<DataDictionaryItemDto>> resultData=new ResultData<>();
        try {
            List<DataDictionaryItemPo> dataDictionaryItemPos = dataDictionaryService.queryItemListByTypeCode(typeCode);
            List<DataDictionaryItemDto> dataDictionaryItemDtos=BeanJsonUtil.listConvert(dataDictionaryItemPos,DataDictionaryItemDto.class);
            resultData.setData(dataDictionaryItemDtos);
            return resultData;
        } catch (Exception e) {
            LOGGER.error("查询数据字段明细出现异常--error:{}",ExceptionUtils.getFullStackTrace(e));
            resultData.setCode(ErrorCode.QUERY_FAILOR);
            resultData.setMessage(ErrorCode.QUERY_FAILOR_MSG);
            return resultData;
        }
    }
}
